package cn.myframe.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import cn.myframe.core.R;
import cn.myframe.redis.RedisService;

/**
 * 系统日志，切面处理类
 * 
 * @author ynz
 * @email ynz@myframe.cn
 * @date 2018年9月27日 上午10:28:00
 */
@Aspect
@Component
public class CheckRedisAspect {
	
	@Autowired
	private RedisService redisService;
	
	
	@Pointcut("@annotation(cn.myframe.annotation.CheckRedis)")
	public void pointCut() { 
		
	}
/*	
	@Before("logPointCut()")
	public void CheckRedis(JoinPoint joinPoint) {
		try{
			//判断redis是否可用
			redisService.get("1");
		}catch(Exception e){
			throw new RRException(BaseDataUtils.getSysterm("redisStop"));
		}
	}
	*/
	
	@Around("pointCut()")
	public Object CheckRedis(ProceedingJoinPoint  joinPoint) throws Throwable{
	   try{
			//判断redis是否可用
			redisService.get("1");
			Object o = joinPoint.proceed();
			return o;
		}catch(Exception e){
			return R.error("redis连接失败！");
			//throw new RRException(BaseDataUtils.getSysterm("redisStop"));
		}
	}
}
